package com.szewec.service.impl;

import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.szewec.common.util.PageInfo;
import com.szewec.mapper.UserMapper;
import com.szewec.model.vo.UserModel;
import com.szewec.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserServiceImpl implements IUserService{

    @Autowired
    UserMapper userMapper;

    @Override
    public void insert(UserModel user) throws Exception {
        userMapper.insert(user);
    }

    @Override
    public void delete(String ids) throws Exception {
        String[] idArr = ids.split(",");
        if(idArr.length < 1) {
            return;
        }
        for(int i=0;i<idArr.length;i++) {
            userMapper.deleteByPrimaryKey(idArr[i]);
        }
    }

    @Override
    public void update(UserModel user) throws Exception {
        userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public PageInfo<UserModel> selectPage(Page<UserModel> page, Wrapper<UserModel> wrapper) throws Exception {
        List<UserModel> userModelList = userMapper.selectPage(page, wrapper);
        PageInfo<UserModel> pageInfo = new PageInfo<UserModel>(userModelList,userModelList.size(),page.getSize(),page.getPages(),page.getCurrent());
        return pageInfo;
    }
}
